const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    newsPasswordShow:false,
    newsPasswordShow2:false,
    originalPasswordVal:'',
    newsPasswordVal:'',
    confirmNewsPasswordVal:''
  },

  passwordShowChange(){
    this.setData({
      newsPasswordShow:!this.data.newsPasswordShow
    })
  },

  passwordShowCon(){
    this.setData({
      newsPasswordShow2:!this.data.newsPasswordShow2
    })
  },

  // 原密码
  originalPasswordInp:function(e){
    this.setData({
      originalPasswordVal: e.detail.value
    })
  },
  // 新密码
  newsPasswordInp: function (e) {
    this.setData({
      newsPasswordVal: e.detail.value
    })
  },
  // 确认新密码
  confirmNewsPasswordInp: function (e) {
    this.setData({
      confirmNewsPasswordVal: e.detail.value
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // this.modifPassword()
  },
  modifPassword:function(){
    var { originalPasswordVal, newsPasswordVal, confirmNewsPasswordVal } = this.data;
    if (originalPasswordVal == ''){
      wx.showToast({
        title: '请输入原密码',
        icon: 'none',
        duration: 2000
      })
      return false;
    }
    if (newsPasswordVal == '' || confirmNewsPasswordVal == ''){
      wx.showToast({
        title: '请输入新密码',
        icon: 'none',
        duration: 2000
      })
      return false;
    }
    if (newsPasswordVal != confirmNewsPasswordVal){
      wx.showToast({
        title: '密码输入不一致',
        icon: 'none',
        duration: 2000
      })
      return false;
    }
    wx.showLoading({
      title: '加载中',
    })
    wx.request({
      url: app.globalData.baseUrl + 'user/updatePassword',
      data: {
        oldPass: originalPasswordVal,
        password: newsPasswordVal,
        repassword: confirmNewsPasswordVal,
        token:app.globalData.token
      },
      method: "POST",
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      success(res) {
        wx.hideLoading()
        if (res.data.code == 1000) {
          wx.showToast({
            title: "修改成功",
            icon: 'success',
            duration: 2000
          })
          setTimeout(()=>{
            wx.navigateBack({
              delta: 1
            })
          },1500)

        } else {
          wx.showToast({
            title: res.data.message,
            icon: 'none',
            duration: 2000
          })
        }
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})
